package com.wicket.okrframework.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrframework.base.service.MDutyTargetDetailService;
import com.wicket.okrframework.base.service.dto.req.QueryTargetDetailsListReq;
import com.wicket.okrframework.biz.service.dto.common.OrgDutyTargetDetailDto;
import com.wicket.okrframework.biz.service.dto.req.AddTargetDetailsReqDto;
import com.wicket.okrframework.biz.service.dto.req.QueryTargetDetailsListReqDto;
import com.wicket.okrframework.biz.service.dto.req.UpdateTargetDetailReqDto;
import com.wicket.okrframework.biz.service.dto.res.AddTargetDetailsRespDto;
import com.wicket.okrframework.biz.service.dto.res.QueryTargetDetailsListRespDto;
import com.wicket.okrframework.biz.service.dto.res.UpdateTargetDetailRespDto;
import com.wicket.okrframework.common.util.RedisUtil;
import com.wicket.okrframework.dal.po.mbg.DutyTargetDetail;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import com.wicket.okrframework.common.exception.Assert;
import java.util.ArrayList;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class FunctionalGoalServiceImpl
        implements com.wicket.okrframework.biz.service.FunctionalGoalService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private MDutyTargetDetailService mDutyTargetDetailService;

    /**
   * D1-3新增目标职责明细[810]
   * gen by moon at 10/2/2022, 7:48:59 AM
   */
  @Trace(operationName = "D1-3新增目标职责明细")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public AddTargetDetailsRespDto addTargetDetails(AddTargetDetailsReqDto reqDto){
    
      
      String string_1 =null;
//步骤0: 1-3-10新增目标职责明细 - addTargetDetails
     String string = null;
    DutyTargetDetail dutyTargetDetail=new DutyTargetDetail();
  if(reqDto!=null){
      dutyTargetDetail.setDetailType(reqDto.getDetailType());//SimpleFieldAssign//sourceId:38506_1
dutyTargetDetail.setContent(reqDto.getContent());//SimpleFieldAssign//sourceId:38507_1
dutyTargetDetail.setOrderNumber(reqDto.getOrderNumber());//SimpleFieldAssign//sourceId:38508_1
dutyTargetDetail.setTypeCode(reqDto.getTypeCode());//SimpleFieldAssign//sourceId:38509_1
dutyTargetDetail.setEntityId(reqDto.getEntityId());//SimpleFieldAssign//sourceId:38510_1
dutyTargetDetail.setOrganizationId(reqDto.getOrganizationId());//SimpleFieldAssign//sourceId:49563_1
dutyTargetDetail.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:49461_1
    }
  
    /*1-3-10新增目标职责明细[177]   */
    Assert.isNull(dutyTargetDetail.getDetailType(),"D1-3新增目标职责明细-1-3-10新增目标职责明细-类型编码不能为空",false);
Assert.isNull(dutyTargetDetail.getContent(),"D1-3新增目标职责明细-1-3-10新增目标职责明细-明细内容不能为空",false);
Assert.isNull(dutyTargetDetail.getOrderNumber(),"D1-3新增目标职责明细-1-3-10新增目标职责明细-排序不能为空",false);
Assert.isNull(dutyTargetDetail.getTypeCode(),"D1-3新增目标职责明细-1-3-10新增目标职责明细-所属对象实例类型不能为空",false);
Assert.isNull(dutyTargetDetail.getEntityId(),"D1-3新增目标职责明细-1-3-10新增目标职责明细-所属对象实例ID不能为空",false);
Assert.isNull(dutyTargetDetail.getSubjectLifeCycle(),"D1-3新增目标职责明细-1-3-10新增目标职责明细-主体生命周期不能为空",false);
      string = mDutyTargetDetailService.addTargetDetails(dutyTargetDetail);
      

      string_1 = string;
    
AddTargetDetailsRespDto retData = new AddTargetDetailsRespDto();
  if(string_1!=null){
      retData.setDutyTargetDetailId(string_1);//SimpleFieldAssign//sourceId:38514_1
    }
  

  
  
return retData;
  }

    /**
   * D1-3 查询目标职责明细列表[813]
   * gen by moon at 10/2/2022, 7:49:24 AM
   */
  @Trace(operationName = "D1-3 查询目标职责明细列表")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public QueryTargetDetailsListRespDto queryTargetDetailsList(QueryTargetDetailsListReqDto reqDto){
    
      
      List<DutyTargetDetail> listDutyTargetDetail_1 =new ArrayList<>();
//步骤0: 1-3-10查询目标职责明细列表 - queryTargetDetailsList
     List<DutyTargetDetail> listDutyTargetDetail =new ArrayList<>();
    QueryTargetDetailsListReq queryTargetDetailsListReq=new QueryTargetDetailsListReq();
  if(reqDto!=null){
      queryTargetDetailsListReq.setTypeCode(reqDto.getTypeCode());//SimpleFieldAssign//sourceId:20604_1
queryTargetDetailsListReq.setEntityId(reqDto.getEntityId());//SimpleFieldAssign//sourceId:20605_1
queryTargetDetailsListReq.setDetailType(reqDto.getDetailType());//SimpleFieldAssign//sourceId:20603_1
queryTargetDetailsListReq.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:20608_1
queryTargetDetailsListReq.setIsArchive(reqDto.getIsArchive());//SimpleFieldAssign//sourceId:39281_1
queryTargetDetailsListReq.setOrganizationId(reqDto.getOrganizationId());//SimpleFieldAssign//sourceId:49673_1
    }
  
    /*1-3-10查询目标职责明细列表[181]   */
    Assert.isNull(queryTargetDetailsListReq.getTypeCode(),"D1-3 查询目标职责明细列表-1-3-10查询目标职责明细列表-所属对象实例类型不能为空",false);
Assert.isNull(queryTargetDetailsListReq.getEntityId(),"D1-3 查询目标职责明细列表-1-3-10查询目标职责明细列表-所属对象实例ID不能为空",false);
      listDutyTargetDetail = mDutyTargetDetailService.queryTargetDetailsList(queryTargetDetailsListReq);
      
      listDutyTargetDetail_1 = listDutyTargetDetail;
    
QueryTargetDetailsListRespDto retData = new QueryTargetDetailsListRespDto();
  retData.setOrgDutyTargetDetailList(listDutyTargetDetail_1.stream().map(item -> BeanUtil.toBean(item, OrgDutyTargetDetailDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:20654_1
  

  
  
return retData;
  }

    /**
   * D1-3修改目标职责明细[811]
   * gen by moon at 10/2/2022, 7:49:10 AM
   */
  @Trace(operationName = "D1-3修改目标职责明细")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public UpdateTargetDetailRespDto updateTargetDetail(UpdateTargetDetailReqDto reqDto){
    
      
      //步骤0: 1-3-10修改目标职责明细 - updateTargetDetail
     boolean bOOLEAN ;
    DutyTargetDetail dutyTargetDetail=new DutyTargetDetail();
  if(reqDto!=null){
      dutyTargetDetail.setDutyTargetDetailId(reqDto.getDutyTargetDetailId());//SimpleFieldAssign//sourceId:38668_1
dutyTargetDetail.setContent(reqDto.getContent());//SimpleFieldAssign//sourceId:38669_1
dutyTargetDetail.setOrderNumber(reqDto.getOrderNumber());//SimpleFieldAssign//sourceId:38670_1
dutyTargetDetail.setSubjectLifeCycle(reqDto.getSubjectLifeCycle());//SimpleFieldAssign//sourceId:49465_1
dutyTargetDetail.setIsArchive(reqDto.getIsArchive());//SimpleFieldAssign//sourceId:49802_1
    }
  
    /*1-3-10修改目标职责明细[179]   */
    
      bOOLEAN = mDutyTargetDetailService.updateTargetDetail(dutyTargetDetail);
      
      


UpdateTargetDetailRespDto retData = new UpdateTargetDetailRespDto();
  
  

  
  
return retData;
  }
    //
}
